package com.hhkj.admin.order.common.component.validator;

import cn.hutool.core.util.ObjectUtil;
import com.hhkj.admin.course.domain.Course;
import com.hhkj.admin.order.common.exception.InvalidOrderItemException;
import com.hhkj.admin.order.domain.OrderItem;
import lombok.AllArgsConstructor;

import java.util.Map;

@AllArgsConstructor
public class AppCourseValidateStrategy extends BaseOrderItemValidateStrategy{

    /** （课程id-课程信息）映射表 **/
    private Map<Long, Course> courseMap;

    /**
     * 校验科目是否存在
     * @param orderItem
     * @return
     * @throws InvalidOrderItemException
     */
    @Override
    public boolean validate(OrderItem orderItem) throws InvalidOrderItemException {
        Course course = courseMap.get(orderItem.getCourseId());
        if (ObjectUtil.isEmpty(course)) {
            throw new InvalidOrderItemException("该类目不存在");
        }
        orderItem.setCourseName(course.getName());
        return false;
    }
}
